//
//  MaintabBar.m
//  OC_WeiboApp
//
//  Created by 李旭阳 on 15/11/25.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "MaintabBar.h"

@interface MaintabBar()
@property(nonatomic,weak)UIButton *plusBtn;
@end

@implementation MaintabBar

- (instancetype)init
{
    self = [super init];
    if (self) {
        UIButton *plusBtn = [[UIButton alloc] init];
        
        //设置button 不同状态的背景图片
        [plusBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [plusBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        
        //设置button不同状态的image
        [plusBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [plusBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        
        [plusBtn addTarget:self action:@selector(plusBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:plusBtn];
        self.plusBtn = plusBtn;
        
        plusBtn.size = plusBtn.currentBackgroundImage.size;
        
    }
    return self;
}

#pragma mark 设置farme
-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.plusBtn.centerX = self.width *0.5;
    self.plusBtn.centerY = self.height *0.5;
    
    CGFloat tabberBtnW = self.width * 0.2;
    
    NSInteger index = 0;
    
    for(int i = 0; i < self.subviews.count ; i++) {
        UIView *view = self.subviews[i];
        if ([view isKindOfClass:NSClassFromString(@"UITabBarButton")]){
            view.width = tabberBtnW;
            view.x = index * tabberBtnW;
            
            if (index == 1) {
                index ++;
            }
            index ++;
        }
    }
}

-(void)plusBtnClick: (UIButton *)btn{
    if ([self.delegate respondsToSelector:@selector(tabBar: plusBtnDidClicked:)]) {
        [self.delegate tabBar:self plusBtnDidClicked:btn];
    }
}

@end
